
import javax.swing.*;
import java.util.regex.*;

public class Ordine extends Responsabil {
    private JFrame f;
    Ordine(JFrame f){
        this.f = f;
    }
    public boolean test(String s){
        boolean rez1 = true;
        Pattern p1 = Pattern.compile("^M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$");//expresie regulata pentru ordinea corecta a cifrelor romane
        Matcher m = p1.matcher(s);
        rez1 = m.matches();
        if(rez1 == false)
            mesaj(f);
        else{
            if(this.next != null)
                next.test(s);
        }
        return rez1;
    }
    public void mesaj(JFrame f){
    	JOptionPane.showMessageDialog(f, "Ati introdus un cuvant care contine in ordine incorecta cifrele romane", "Eroare", JOptionPane.ERROR_MESSAGE);
    	System.exit(1);
    }

}
